package com.okaysoft.ofb

import com.okaysoft.ofb.account.Role
import com.okaysoft.ofb.account.UserRole

class Terminal {

    String area //区块号
    String terId //端子标识
    String number //编号
    String letter      //盘符
    String letterNumber //盘号
    String code //编码
    String logo //现场标识
    Status status //状态
    Boolean opening //是否开通
    String segmentName // 光缆段名称
    String opticalNumber //光蕊序号
    Boolean vip //是否VIP用户
    BackboneWiring  backboneWiring//主干或配线 ,false主干，true 配线
    String businessType //业务类型
    String splitterModel//光分器型号
    String splitRatio //分光比
    String jumperPort //跳接端口
    Boolean splitter //有无分光
    String opticalSplitterPorts // 光分器连接端口
    String tiaoQianCode //跳纤号
    String superiorTerminal //上级端子  端子代码
    String description //备注
    ClientUser clientUser //通信用户
    String deviceName //   箱子名称
    String deviceTerminal//  箱子中的端子编号

    static belongsTo = [device:Device]
    static constraints = {
        logo(nullable: true)
        status(nullable: true)
        opening(nullable: true)
        segmentName(nullable: true)
        opticalNumber(nullable: true)
        vip(nullable: true)
        backboneWiring(nullable: true)
        businessType(nullable: true)
        splitterModel(nullable: true)
        splitRatio(nullable: true)
        jumperPort(nullable: true)
        splitter(nullable: true)
        opticalSplitterPorts(nullable: true)
        superiorTerminal(nullable: true)
        clientUser(nullable: true)
        description(nullable: true)
        tiaoQianCode(nullable: true)
        deviceName(nullable: true)
        deviceTerminal(nullable: true)
    }

    enum Status {
        DAMAGE(0, '损坏端子'),
        //WELDING(1, '未熔接端子'),
        WELDING_NO_JUMPER(2, '未跳接端子'),
        JUMPER(3, '已跳接端子')
        /*VIP(4, 'VIP用户端子端子'),*/
        /*TASK(5, '有任务关联端子')*/
        String label
        int id

        Status(int id, String label) {
            this.id = id
            this.label = label
        }
    }

    enum BackboneWiring {
        NOTHING(0, '未设置'),
        BACKBONE(1, '主干'),
        WIRING(2, '配线')
        String label
        int id

        BackboneWiring(int id, String label) {
            this.id = id
            this.label = label
        }
    }

    static mapping = {
        number(unique: true)
    }

    Set<ClientUser> getClientUsers() {
        TerminalClientUser.findAllByTerminal(this).collect { it.clientUser } as Set
    }
}
